package com.yang.frost.blueberry.controller;

import com.yang.frost.blueberry.config.annotation.Log;
import com.yang.frost.blueberry.util.ApiResult;
import com.yang.frost.blueberry.weixin.params.WxBaseParam;
import com.yang.frost.blueberry.weixin.service.WxMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 10296
 * @date 2021/4/14
 * @Description: 微信公众号---菜单管理
 */
@RestController
@RequestMapping("/wxMenuApi")
@Api(value = "微信公众号菜单管理API", tags = {"微信公众号菜单管理"})
public class WxMenuController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private WxMenuService menuService;


    @Log("微信公众号-->菜单管理-->创建菜单")
    @PostMapping("/createMenu")
    @ApiOperation(value = "微信公众号-->菜单管理-->创建菜单", notes = "微信公众号-->菜单管理-->创建菜单")
    public ApiResult createMenu(WxBaseParam params, HttpServletResponse response) {
        Map<String, Object> menu = new HashMap<>();
        try {
            menu = menuService.createMenu(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ApiResult.ok(menu);
    }

    @Log("微信公众号-->菜单管理-->查询自定义菜单")
    @PostMapping("/getCurrentSelfMenuInfo")
    @ApiOperation(value = "微信公众号-->菜单管理-->查询自定义菜单", notes = "微信公众号-->菜单管理-->查询自定义菜单")
    public ApiResult getCurrentSelfMenuInfo(WxBaseParam params, HttpServletResponse response) {
        Map<String, Object> menu = new HashMap<>();
        try {
            menu = menuService.getCurrentSelfMenuInfo(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ApiResult.ok(menu);
    }

    @Log("微信公众号-->菜单管理-->删除菜单")
    @PostMapping("/deleteMenu")
    @ApiOperation(value = "微信公众号-->菜单管理-->查询自定义菜单", notes = "微信公众号-->菜单管理-->查询自定义菜单")
    public ApiResult deleteMenu(WxBaseParam params, HttpServletResponse response) {
        Map<String, Object> menu = new HashMap<>();
        try {
            menu = menuService.deleteMenu(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ApiResult.ok(menu);
    }


}
